/**
 * Copyright(c)2012 Beijing PeaceMap Co.,Ltd.
 * All right reserved. 
 */
package com.pmc.dwa.common.utils;

import java.util.List;

/**
 * @description 分页工具类
 * @author aokunsang
 * @date 2013-1-5
 */
public class PaginationSupport<E> {

	private final static int PAGE_PER_SIZE = 10;   //默认每页显示条数[对easyui的分页来说，这个参数没有作用]
	
	private List<E> items;
	private long totalCount;  //记录总条数
	private int pageNumber;   //当前页码
	private int pageSize;    //每页显示条数
	
	public PaginationSupport(List<E> items,long totalCount,int pageNumber,int pageSize){
		this.items = items;
		this.totalCount = totalCount;
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
	}
	
	public PaginationSupport(List<E> list,long totalCount,int pageNumber){
		this(list,totalCount,pageNumber,PAGE_PER_SIZE);
	}
	
	/* 获取当前页的第一条记录数 */
	public long getFirstIndex() {
		return (pageNumber-1) * pageSize;
	}
	
	/* 获取总页数  */
	public long getPageCount() {
		return (totalCount + pageSize - 1) / pageSize;
	}

	/**
	 * @return the totalCount
	 */
	public long getTotalCount() {
		return totalCount;
	}

	/**
	 * @param totalCount the totalCount to set
	 */
	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	/**
	 * @return the pageNumber
	 */
	public int getPageNumber() {
		return pageNumber;
	}

	/**
	 * @param pageNumber the pageNumber to set
	 */
	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the items
	 */
	public List<E> getItems() {
		return items;
	}

	/**
	 * @param items the items to set
	 */
	public void setItems(List<E> items) {
		this.items = items;
	}
}
